import csv
import random

random.seed(20221126)
o_data = []
with open('./data/data.csv', 'r', encoding='utf-8-sig') as f:
    reader = csv.reader(f)
    for row in reader:
        o_data.append(row)

names_a = {}
names_b = {}
names_c = {}
for row in o_data[1: ]:
    for i, v in enumerate(row):
        if i == 0:
            names_a[v] = ''
        elif i in [1,2,3]:
            names_b[v] = ''
        else:
            names_c[v] = ''

c_name_choices = list(set(random.choices(list(names_c), k = 20)))
for k in names_c.keys():
    names_c[k] = random.choice(c_name_choices)


excel_like_data_set = []
excel_like_incell_data = []
max_index = 0
for row in o_data[1: ]:
    excel_like_data_row = []
    a_names = []
    b_names = []
    c_names = []
    for i, v in enumerate(row):
        if v != '':
            if i == 0:
                a_names.append(v) 
            elif i in [1, 2, 3]:
                b_names.append(v)
            else:
                c_names.append(names_c[v])
    c_names = list(set(c_names))
    excel_like_incell_data.append([a_names[0], ','.join(b_names), ','.join(c_names)])
    excel_like_data_set.append([a_names, b_names, c_names])
    if max_index < len(c_names):
        max_index = len(c_names)

excel_like_data = []
for row in excel_like_data_set:
    b_names = ['', '', '']
    for i, v in enumerate(row[1]):
        b_names[i] = v
    c_names = ['' for _ in range(max_index)]
    for i, v in enumerate(row[2]):
        c_names[i] = v
    excel_like_data.append([row[0][0]] + b_names + c_names)

with open('./data/fake_excel_like.csv', 'w+',encoding='utf-8-sig', newline='') as f:
    writer = csv.writer(f)
    writer.writerows(excel_like_data)

with open('./data/fake_excel_like_incell.csv', 'w+', encoding='utf-8-sig', newline='') as f:
    writer = csv.writer(f)
    writer.writerows(excel_like_incell_data)